<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>03_JS数据类型</title>
</head>
<body>
<script>
    //数据类型=原始类型*引用类型
    //原始类型：number,string,boolean,undefined,null
    var a = 10;
    var b = 3.14;
    console.log(a,typeof a,b,typeof b);
    var c = "hello";
    var d = 'world';
    console.log(c,typeof c,d,typeof d);
    var e = true;
    var f = false;
    console.log(e,typeof e,f,typeof f);
    var g;//声明了变量，但未赋值，推断不出来类型，就是定义型
    console.log(g,typeof g);//undefined未定义型

    let obj = {}
    console.log(obj,typeof obj);
    obj.name="张三";
    obj.age = 18;
    console.log(obj);

    let obj2={
        name:"张三",
        age:18
    }
    console.log(obj2);
    obj2.like ="吃火锅";
    console.log(obj2);
    console.log(obj2.name,obj2.age);
    console.log(obj2.play);//访问对象不存在的属性，返回undefined


    //数组
    let arr = [1,3.14,true,"张三"];
    console.log(arr,typeof arr);//[1, 3.14, true, '张三'] object
    console.log(arr[0],arr[1],arr[2],arr[3]);
    console.log(arr[99]);//访问数组不存在的下标，返回undefined

    //Number():将数据转换为数学类型的结果，如果得不到数字类型的结果就会得到NaN
    console.log(Number(true),typeof Number(true));//1  number
    console.log(Number(false));//0  number
    console.log(Number('123'));//123  number
    console.log(Number(23.5));//23.5  number
    console.log(Number("hhh"));//NaN(Not a Number)

    //Boolean():将数据转换为布尔类型的结果
    console.log(Boolean(false));
    console.log(Boolean(0));
    console.log(Boolean(null));
    console.log(Boolean(undefined));
    console.log(Boolean(''));
    console.log(Boolean(' '));

</script>
</body>
</html>